package com.controller;

 import com.common.contant.RestResponse;
import com.service.SpecificationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: sijunqiang
 * @Date: 2020/6/3 11:10
 * @Description: 商品规格属性控制层
 */
@RestController
@Slf4j
@RequestMapping(value = "/spec")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SpecificationController {

    private final SpecificationService specificationService;

    /**
     * 根据商品分类的id 查询出对应的规格组列表
     *
     * @param id 商品分类的id
     * @return 规格组列表
     */
    @RequestMapping(value = "/groups/of/category")
    public RestResponse queryGroupInfoByCategoryId(@RequestParam("id") Long id) {
        log.info(">>>>开始: 根据商品分类的id:[{}],查询出对应的规格组列表", id);
        return specificationService.queryGroupInfoByCategoryId(id);
    }


    /**
     * 根据规格组的id 查询规格参数的列表
     *
     * @param gid 规格组id
     * @return 规格参数列表
     */
    @RequestMapping(value = "/params")
    public RestResponse querySpecParams(@RequestParam(value = "gid") Long gid) {
        log.info(">>>开始: 根据规格组的id:[{}],查询规格参数的列表>>>", gid);
        return specificationService.querySpecParams(gid);
    }
}
